// 1. 基础组件接口
interface MilkTea {
    String getDescription();
    int getCost();
}

// 2. 具体组件实现
class OriginalMilkTea implements MilkTea {
    @Override
    public String getDescription() {
        return "原味奶茶";
    }

    @Override
    public int getCost() {
        return 10;
    }
}

// 3. 抽象装饰器
abstract class MilkTeaDecorator implements MilkTea {
    protected MilkTea decoratedMilkTea;

    public MilkTeaDecorator(MilkTea milkTea) {
        this.decoratedMilkTea = milkTea;
    }

    public String getDescription() {
        return decoratedMilkTea.getDescription();
    }

    public int getCost() {
        return decoratedMilkTea.getCost();
    }
}

// 4. 具体装饰器实现
class PearlDecorator extends MilkTeaDecorator {
    public PearlDecorator(MilkTea milkTea) {
        super(milkTea);
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + 珍珠";
    }

    @Override
    public int getCost() {
        return super.getCost() + 2;
    }
}

class PuddingDecorator extends MilkTeaDecorator {
    public PuddingDecorator(MilkTea milkTea) {
        super(milkTea);
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + 布丁";
    }

    @Override
    public int getCost() {
        return super.getCost() + 3;
    }
}

class CoconutDecorator extends MilkTeaDecorator {
    public CoconutDecorator(MilkTea milkTea) {
        super(milkTea);
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + 椰果";
    }

    @Override
    public int getCost() {
        return super.getCost() + 2;
    }
}

// 客户端使用
public class DecoratorDemo {
    public static void main(String[] args) {
        // 基础奶茶
        MilkTea order = new OriginalMilkTea();
        System.out.println(order.getDescription() + " 价格：" + order.getCost());

        // 加珍珠和椰果
        order = new PearlDecorator(order);
        order = new CoconutDecorator(order);
        System.out.println(order.getDescription() + " 价格：" + order.getCost());

        // 再加布丁
        order = new PuddingDecorator(order);
        System.out.println(order.getDescription() + " 价格：" + order.getCost());
    }
}
